<template>
  <div class="page-box">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <!--      <el-form-item>-->
      <!--        <TowerElect v-model="state.dataForm.stationId" placeholder="所属杆塔" clearable></TowerElect>-->
      <!--      </el-form-item>-->
      <el-form-item>
        <el-input v-model="state.dataForm.businessType" placeholder="数据类型" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-date-picker style="width: 100%" v-model="pictureDate" value-format="YYYY-MM-DD HH:mm:ss"
                        type="datetimerange" range-separator="至" start-placeholder="开始日期"
                        end-placeholder="结束日期" unlink-panels :shortcuts="shortcuts"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button @click="state.getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <!--      <el-form-item>-->
      <!--        <el-button type="info" @click="state.exportHandle()">{{ $t("export") }}</el-button>-->
      <!--      </el-form-item>-->
      <!--      <el-form-item>-->
      <!--        <el-button v-if="state.hasPermission('KxSensorUnusual:kxsensorunusual:save')" type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>-->
      <!--      </el-form-item>-->
      <!--      <el-form-item>-->
      <!--        <el-button v-if="state.hasPermission('KxSensorUnusual:kxsensorunusual:delete')" type="danger" @click="state.deleteHandle()">{{ $t("deleteBatch") }}</el-button>-->
      <!--      </el-form-item>-->
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
<!--      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>-->
<!--      <el-table-column prop="id" label="id" header-align="center" align="center"></el-table-column>-->
<!--      <el-table-column prop="stationId" label="" header-align="center" align="center"></el-table-column>-->
      <el-table-column prop="stationName" label="所属杆塔" header-align="center" align="center"></el-table-column>
      <el-table-column prop="businessType" label="数据类型" header-align="center" align="center"></el-table-column>
      <el-table-column prop="type" label="预警类型" header-align="center" align="center"></el-table-column>
<!--      <el-table-column prop="businessId" label="" header-align="center" align="center"></el-table-column>-->
      <el-table-column prop="processingStatus" label="处理状态" header-align="center" align="center">
        <template v-slot="scope">
          {{ state.getDictLabel("processing_status", scope.row.processingStatus) }}
        </template>
      </el-table-column>
<!--      <el-table-column prop="procInstId" label="流程实例id" header-align="center" align="center"></el-table-column>-->
      <el-table-column prop="uploadDate" label="预警时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="actName" label="处理环节" header-align="center" align="center"></el-table-column>
      <el-table-column prop="handleUserName" label="处理人" header-align="center" align="center"></el-table-column>
<!--      <el-table-column prop="componentId" label="传感器 ID" header-align="center" align="center"></el-table-column>-->
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="scope.row.processingStatus != 'processNotStart'"
                     type="primary" link @click="addOrUpdateHandle(scope.row)">详情
          </el-button>
          <el-button v-if="scope.row.processingStatus == 'processNotStart'"
                     type="danger" link @click="addOrUpdateHandle(scope.row)">消缺
          </el-button>
          <!--          <el-button v-if="state.hasPermission('KxSensorUnusual:kxsensorunusual:update')" type="primary" link @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>-->
          <!--          <el-button v-if="state.hasPermission('KxSensorUnusual:kxsensorunusual:delete')" type="primary" link @click="state.deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>-->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit" :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <WarningDataFrom ref="warningdatafrom" @close="close"></WarningDataFrom>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { nextTick, reactive, ref, toRefs, watch } from "vue";
import WarningDataFrom from "@/views/KxSensorUnusual/warningDataFrom.vue";
import {useRoute, useRouter} from 'vue-router';
import TowerElect from "@/components/tower-elect.vue";
import shortcuts from "@/utils/timeHorizon";

const view = reactive({
  getDataListURL: "/KxSensorUnusual/kxsensorunusual/page",
  getDataListIsPage: true,
  exportURL: "/KxSensorUnusual/kxsensorunusual/export",
  deleteURL: "/KxSensorUnusual/kxsensorunusual",
  deleteIsBatch: true,
  dataForm: {
    id: null,
    stationId: "",
    businessType: "",
    startTime: "",
    endTime: ""
  }
});

const state = reactive({ ...useView(view), ...toRefs(view) });

const pictureDate = ref([] as any)
watch(pictureDate, (val) => {
  console.log(val)
  if (val === null) {
    state.dataForm.startTime = "";
    state.dataForm.endTime = "";
  } else {
    state.dataForm.startTime = val[0];
    state.dataForm.endTime = val[1];
  }
}, {deep: true})

const addKey = ref(0);
const addOrUpdateRef = ref();

const close = () => {
  state.getDataList();
}

const warningdatafrom = ref();
const planDataFrom = ref();

const addOrUpdateHandle = (data?: any) => {
  nextTick(() => {
    warningdatafrom.value.init(data, "processNotStart");
  });
};

const route: any = useRoute();
const router: any = useRouter();
console.log("---", route.params);

if (route.query.data !== undefined) {
  console.log(JSON.parse(route.query.data))
  const paramValue: any = JSON.parse(route.query.data);
  addOrUpdateHandle(paramValue)
  router.push({
    path: "/KxSensorUnusual/kxsensorunusual",
    query: {}
  });
  delete route.query.data;
}
</script>
